package m1;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws Exception {
        //建立连接
       ConnectionFactory f =  new ConnectionFactory();
       f.setHost("192.168.64.140");
       f.setPort(5672);
       f.setUsername("admin");
       f.setPassword("admin");
       Connection conn = f.newConnection();//网络连接
       Channel c = conn.createChannel(); //通信通道
        //定义helloworld队列，服务器不存在这个队列会新建队列 反之直接使用已存在的队列
        //在这里告诉服务器 让服务器准备好这个队列
        c.queueDeclare("helloworld", false, false, false, null);

        //发送消息
        c.basicPublish("", "helloworld", null, "Hello World!".getBytes());
        System.out.println("消息已发送");
    }
}
